package org.jeecg.modules.front.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.front.entity.WorkOrder;
import org.jeecg.modules.front.mapper.HomeWorkOrderMapper;
import org.jeecg.modules.front.model.WorkOrderModel;
import org.jeecg.modules.front.service.HomeWorkOrderService;
import org.jeecg.modules.front.vo.*;
import org.springframework.stereotype.Service;
import java.util.List;

@Slf4j
@Service
public class HomeWorkOrderServiceImpl  extends ServiceImpl<HomeWorkOrderMapper, WorkOrder> implements HomeWorkOrderService {
    @Override
    public OrdersVo module1() {
        
     int todayNums=this.baseMapper.count(0);   //今日工单总数量
        double avg=this.baseMapper.avg();
        int zNums=this.baseMapper.count(1);
        int wNuns=this.baseMapper.count(7);
        OrdersVo vo=new OrdersVo();
        vo.setAverage(avg);
        vo.setCount(todayNums);
        if(zNums!=0){
           vo.setYoY( (todayNums-zNums)/zNums*100);
        }else{
            vo.setYoY(todayNums*100);
        }
        if(wNuns!=0){
            vo.setWeekly( (todayNums-zNums)/zNums*100);
        }else{
            vo.setWeekly(todayNums*100);
        }
        return vo;
    }

    @Override
    public CompleteVo module2() {
    int finishes=this.baseMapper.finish(6);
    int finish=this.baseMapper.finish(0);   //日完成量
        List<CompleteOrderVo> list=this.baseMapper.finishList(7);
        CompleteVo vo=new CompleteVo();
        vo.setCompleteOrders(finishes);
        vo.setTodayCompleteOrder(finish);
        vo.setList(list);
        return vo;
    }

    @Override
    public OrderCompletionRateVo module3() {
        OrderCompletionRateVo vo=new OrderCompletionRateVo();
        int todayNums=this.baseMapper.count(0);   //今日工单总数量
        int finish=this.baseMapper.finish(0);   //日完成量
        double dailyCompletionRate;
        if(todayNums==0){
            dailyCompletionRate=todayNums*100;
        }else{
            dailyCompletionRate=finish/todayNums*100;
        }
        vo.setTodayFinishOrdersNumber(finish);
        vo.setDailyCompletionRate(dailyCompletionRate);
        vo.setTodayOrdersNumber(todayNums);
        return vo;
    }

    @Override
    public List<TicketPersonVo> module4(WorkOrderModel workOrderModel) {
        List<TicketPersonVo>  list =this.baseMapper.individualCompletion(workOrderModel);
        TicketPersonVo vo=new TicketPersonVo();
        vo.setName("暂无人员");
        vo.setCount(0);
        int x=0;
        if(list!=null){
          x=list.size();
        }
        System.out.println(x);
        for (int i=0;i<10-x;i++){
            list.add(vo);
        }
        return list;

    }

    @Override
    public List<TypeVo> orderType() {
        return this.baseMapper.orderType();
    }
}
